package com.tedu._06weibo.controller;

import com.tedu._06weibo.mapper.CommentMapper;
import com.tedu._06weibo.pojo.dto.CommentDTO;
import com.tedu._06weibo.pojo.entity.Comment;
import com.tedu._06weibo.pojo.entity.User;
import com.tedu._06weibo.pojo.vo.CommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import javax.xml.bind.SchemaOutputResolver;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/comment/")
@Api(tags = "评论模块")
public class CommentController {
    @Autowired
    private CommentMapper commentMapper;
    @ApiOperation("发送评论")
    @PostMapping("insert")
    public int insert(@RequestBody CommentDTO commentDTO,@ApiIgnore HttpSession session){
        User user=(User)session.getAttribute("user");
        if(user==null){
            return 2;
        }
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentDTO,comment);
        comment.setUserId(user.getId());
        comment.setCreated(new Date());
        commentMapper.insert(comment);
        return 1;
    }
    @GetMapping("selectByWeiboId")
    @ApiOperation("查询评论")
    @ApiImplicitParam(value = "评论ID",name = "id",required = true,example = "100")
    public List<CommentVO> selectByweiboId(Integer id){
        return commentMapper.selectByWeiboId(id);
    }
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "微博ID",name = "weiboId",required = true,example = "100"),
                    @ApiImplicitParam(value = "用户ID",name = "userId",required = true,example = "100")
            }
    )
    public List<CommentVO> findByWeiboIdAndUserId(Integer weiboId,Integer userId){
        return null;
    }
}
